package com.neusoft.neuiotms.dcom.model.hn;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;

import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.neusoft.bizcore.web.jpa.model.AbstractAuditModel;
import com.neusoft.bizcore.web.jpa.model.Comment;
import com.neusoft.neuiotms.dcom.model.enums.HnInspectionTaskItemStatus;
import com.neusoft.neuiotms.dcom.model.enums.HnInspectionTaskStatus;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name = "neuiot_inspection_task_hn")
@org.hibernate.annotations.Table(appliesTo = "neuiot_inspection_task_hn", comment = "海南日巡检任务计划表")
public class HnInspectionTask extends AbstractAuditModel {

    private static final long serialVersionUID = -6832614692045602075L;

    @ManyToOne
    private HnInspectionPlan hnInspectionPlan;

    @NotBlank(message = "编码")
    @Length(max = 64, message = "编码不能超过{max}位")
    @Column(length = 64, nullable = false, unique = true)
    @Comment("varchar(64) NOT NULL COMMENT '编码'")
    private String code;

    @Column(nullable = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Comment("datetime NOT NULL COMMENT '开始时间'")
    private Date startDateTime;

    @Column(nullable = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Comment("datetime NOT NULL COMMENT '结束时间'")
    private Date endDateTime;

    @Column(nullable = true)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Comment("datetime NULL DEFAULT NULL COMMENT '实际时间'")
    private Date actualDateTime;

    @NotBlank(message = "厅局编码")
    @Length(max = 255, message = "厅局编码不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '厅局编码'")
    private String institutionCode;

    @NotBlank(message = "厅局名称")
    @Length(max = 255, message = "厅局名称不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '厅局名称'")
    private String institutionName;

    @Length(max = 255, message = "执行人编码不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '执行人编码'")
    private String userCode;

    @Length(max = 255, message = "执行人名称不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '执行人名称'")
    private String userName;

    @Length(max = 2047, message = "存在问题不能超过{max}位")
    @Column(length = 2047, nullable = true)
    @Comment("varchar(2047) NULL COMMENT '存在问题'")
    private String problem;

    @Length(max = 2047, message = "解决方法不能超过{max}位")
    @Column(length = 2047, nullable = true)
    @Comment("varchar(2047) NULL COMMENT '解决方法'")
    private String solution;

    @Enumerated(EnumType.STRING)
    @Column(length = 16, nullable = false)
    @Comment("varchar(16) NOT NULL COMMENT '巡检任务状态'")
    private HnInspectionTaskStatus status = HnInspectionTaskStatus.notStarted;

    @OneToMany(mappedBy = "task", cascade = CascadeType.ALL)
    private List<HnInspectionTaskItemValue> itemValues = new ArrayList<>();

    @Enumerated(EnumType.STRING)
    @Column(length = 16, nullable = false)
    private HnInspectionTaskItemStatus itemStatus = HnInspectionTaskItemStatus.uninspected;

    @OneToMany(mappedBy = "task", cascade = CascadeType.ALL)
    private List<HnInspectionTaskAsset> assets = new ArrayList<>();

    /** 在线数量 **/
    private long onlineCount = 0;

}
